<?php

namespace App\Http\Controllers\EmberApi;

use Carbon\Carbon;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Miners\Miner;
use Illuminate\Support\Facades\DB;


class MinerPayoutsController extends Controller
{
    //
    public function index(){
        $activeMiners = Miner::where('status','active')->get();
        foreach ($activeMiners as $activeMiner) {
            $today = Carbon::today()->toDateString();
            $minerPayouts = $activeMiner
                ->payouts()
                ->whereDate('made_at',$today)
                ->get(['amount']);
            $payTodayAmount = 0;
            foreach ($minerPayouts as $minerPayout) {
                //var_dump($minerPayout->amount);
                $payTodayAmount += $minerPayout->amount;
            }
            $activeMiner->pay_today = $payTodayAmount;
            $activeMiner->save();
        }

    }
}
